package com.kiseny.main;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class TestLinkedListVSArrayList {
	
	public static void main (String[] args) {
		
		List<String> linkedList = new LinkedList<String>();
		long start1 = System.currentTimeMillis();
		for (int m = 0; m < 20000; m++) {
			linkedList.add(m, "Hello Word");
		}
		long end1=System.currentTimeMillis();
		System.out.println("Duration: " + (end1 - start1) + "ms");
		//当在200000条数据之前插入20000条数据时，LinkedList只用了1125多ms. 
        //这就是LinkedList的优势所在
		
		List<String> arrayList = new ArrayList<String>();
		long start2 = System.currentTimeMillis();
		for (int n = 0; n < 20000; n++) {
			arrayList.add(n, "Hello Word");
		}
		long end2=System.currentTimeMillis();
		System.out.println("Duration: " + (end2 - start2) + "ms");
		// 当在200000条数据之前插入20000条数据时，ArrayList用了18375多ms.
		// 时间花费是LinkedList的近20倍(视测试时机器性能)

	}

}
